package com.xiguaji.tiktok.v1.product.repository.impl;

import com.xiguaji.tiktok.utils.jdbc.JdbcTemplateKit;
import com.xiguaji.tiktok.utils.jdbc.PageResponse;
import com.xiguaji.tiktok.v1.product.dto.OrderResponse;
import com.xiguaji.tiktok.v1.product.repository.OrderExtRepository;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class OrderExtRepositoryImpl implements OrderExtRepository {

    @Autowired
    JdbcTemplateKit jdbcTemplateKit;

    @Override
    public PageResponse<OrderResponse> getPage(Long uid, int page, int pageSize,Integer type) {
        List<Object> params = new ArrayList<>();
        StringBuffer sql = new StringBuffer();
        sql.append(" FROM product_order ");
        sql.append("WHERE ");
        sql.append("user_id = ? ");
        params.add(uid);
        if(null != type){
            sql.append(" and type = ? ");
            params.add(type);
        }
        sql.append("ORDER BY create_date desc ");
        return jdbcTemplateKit.getPage(OrderResponse.class,page,pageSize,"SELECT * ",sql.toString(),params.toArray());
    }
}
